package com.xiaow.springsecuriydemo.controller;


import com.xiaow.springsecuriydemo.service.UserService;
import com.xiaow.springsecuriydemo.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xiaow
 * @since 2022-09-15
 */
@RestController
@RequestMapping("/user")
//@CrossOrigin(origins = "*")
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("all")
    @PreAuthorize("hasAuthority('/hello')")
    public Result getAll() {
        return Result.succ(userService.list());
    }



    @GetMapping("all2")
    @PreAuthorize("hasAuthority('/hello1')")
    public Result getAll2() {
        return Result.succ(userService.list());
    }


//    使用自定义的权限校验方法
    @GetMapping("all3")
    @PreAuthorize("@ex.hasAuthority('/hello')")
    public Result getAll3() {
        return Result.succ(userService.list());
    }

}
